﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using haptic.src.engine.threads;
using haptic.src.engine.core;

namespace haptic.src.engine.collisions
{
    public class CollisionJob : Job
    {
        public Result Compute()
        {
            return Result.Success;
        }
        public Result SendResults()
        {
            return Result.Success;
        }
    }
    public class CollisionManager
    {
        [Flags]
        public enum ColliderFlags
        {
            E_NONE      = 0,
            E_DEFAULT   = (1<<0)
        }

        public void AddCollider(ICollider oCollider, ColliderFlags eFlags)
        {
            if ((eFlags & ColliderFlags.E_DEFAULT) != 0)
                m_oDefaultColliders.Add(oCollider);
            m_oColliderFlags.Add(oCollider, eFlags);
        }
        public void RemoveCollider(ICollider oCollider)
        {
            if (!m_oColliderFlags.ContainsKey(oCollider))
                return;
            ColliderFlags eFlags = (ColliderFlags)m_oColliderFlags[oCollider];
            if ((eFlags & ColliderFlags.E_DEFAULT) != 0)
                m_oDefaultColliders.Remove(oCollider);

            m_oColliderFlags.Remove(oCollider);
        }

        public CollisionHit CollideFirst(ICollider oCollider, ColliderFlags eFlags)
        {
            CollisionHit oHit = new CollisionHit();
            if ((eFlags & ColliderFlags.E_DEFAULT) != 0)
                foreach (ICollider oC in m_oDefaultColliders)
                {
                    if (oC == oCollider)
                        continue;
                    if (oCollider.IsColliding(oC, oHit))
                        return oHit;
                }
            return null;
        }

        #region Attributes
        private List<ICollider> m_oDefaultColliders = new List<ICollider>();
        private Hashtable m_oColliderFlags = new Hashtable();
        #endregion
    }
}
